package com.xiyou.luckdraw.common.utils;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName ReqUtils
 * @Description HttpServletRequest 公共操作工具
 * @Auther limingxing
 * @Date 2019-10-16 上午10:32
 * @Version 1.0
 **/
public class ReqUtils {

    /**
     * 获取HttpServletRequest
     *
     * @return
     */
    public static HttpServletRequest getRequest() {
        return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    }

    /**
     * 获取签名时间戳
     *
     * @return
     */
    public static String getTimestamp() {
        return getRequest().getHeader("timestamp");
    }

    /**
     * 获取请求的URI
     *
     * @return
     */
    public static String getUri() {
        return getRequest().getRequestURI();
    }

    /**
     * 获取请求方法
     *
     * @return
     */
    public static String getMethod() {
        return getRequest().getMethod().toUpperCase();
    }

    /**
     * 数据源类型(王者: luckdraw,吃鸡: luckyelite)
     * @param
     * @auther limingxing
     * @date 2019-10-16 13:53
     */
    public static String getDatasourceType() {
        return getRequest().getHeader("datasourceType");
    }
}
